package com.example.mqspring.rabiitmqbasicleverone.rabbitmqRPC;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.io.IOException;

public class RPCClient {
//    客户端发送消息请求过去
    public void requestSend(Channel channel, String myQueue,String messageIdentifier,String replyQueue1){

        String requestMessage = "我进行一次RPC访问";
        try {
            channel.queueDeclare(myQueue,true,false,false,null);
//           创建一个临时,私有,自动删除的回复队列
            String replyQueue = replyQueue1;
//            构建属性对象
            AMQP.BasicProperties props = new AMQP.BasicProperties.Builder().correlationId(messageIdentifier).replyTo(replyQueue).build();
//          发送消息过去
            channel.basicPublish("",myQueue,props,requestMessage.getBytes());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
